package com.lichuang.dedao.city.mapper;

import com.lichuang.dedao.city.entity.Note;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lichuang.dedao.city.entity.NoteLike;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 笔记 Mapper 接口
 * </p>
 *
 * @author wp
 * @since 2019-07-13
 */
@Mapper
public interface NoteMapper extends BaseMapper<Note> {

    /**
     * 插入笔记 如果transpond_id=0则为一级笔记。else 为转发笔记的id
     * @param note
     * @return
     */
    @Insert("insert into note(user_id, content, share_img, headline, section, note_status, share_time, whether_course, whether_hear_book, whether_e_book, transpond_id,likes) VALUES (#{user_id},#{content},#{share_img},#{headline},#{section},#{note_status},#{share_time},#{whether_course},#{whether_hear_book},#{whether_e_book},#{transpond_id},#{likes})")
    int instranspond(Note note);


    /**
     * 点赞
     * @param note_id
     * @param likes
     * @return
     */
    @Update("update note set `likes`=`like`+#{likes} where note_id = #{note_id}")
    int updLike(Integer uid,Integer note_id,Integer likes);


    @Select("select * from note_like where note_id = #{note_id} and user_id = #{user_id};")
    NoteLike selLike(Integer user_id, Integer note_id);


    @Update("update note_like set state =#{state} where id = #{id}")
    int updlike(Integer id,Integer state);


    @Insert("insert into note_like (user_id, note_id, state)\n" +
            "values (#{user_id},#{note_id},#{state})")
    int insLike(NoteLike like);







}
